<?php


namespace app\server\controller;

use app\server\model\Servers as ServersModel;  //引入model.
use think\Controller;

class Servers extends Controller
{

    public function get(){
        $user = new ServersModel();
        $data=$this->request->param();
        $d= $user->where($data['field'],$data['op'],$data['value'])
            ->where($data['field1'],$data['op1'],$data['value1'])
            ->with("serverImg")
            ->where('is_delete','=',0)
            ->order($data['order_by'],'desc')
            ->page($data['page'])
            ->limit(10)
            ->select();
        return $d;
    }
    public function getAll(){
        $user = new ServersModel();
        $data=$this->request->param();
        $d= $user->where($data['field'],$data['op'],$data['value'])
            ->with("serverImg")
            ->where('is_delete','=',0)
            ->order($data['order_by'],'desc')
            ->select();
        return $d;
    }
    //按照服务名称查询服务
    public function serverSearch(){
        $res = new ServersModel();
        $data=$this->request->param();
        $a = $data['name'];
        $d =$res->where('name', 'like', '%'.$a.'%')
            ->with("serverImg")
            ->where($data['field'],$data['op'],$data['value'])
            ->order('cTime desc')
            ->select();
        return $d;
    }
    public function update()
    {
        $data = $this->request->param();
        $res = new ServersModel();
        return $res->updateModel($data);
    }
    public function delete(){
        $data = $this->request->param();
        $res = new ServersModel();
        return $res->deleteModel($data);
    }
    public function save(){
        $res = new ServersModel();
        $data = $this->request->param();
        $d= $res->saveModel($data);
        return $d->s_id;
    }
    public function num(){
        $data = $this->request->param();
        $res =new ServersModel();
        return $res->where($data['field'],$data['op'],$data['value'])->count();
    }
    public function buyCountInc(){
        $res = new ServersModel();
        $data = $this->request->param();
        $res->where([$data['field']=>$data['value']])->setInc('buy_count');
    }
}